package com.android.kotlincoroutinemvvmdemo.view
import android.content.Context
import android.graphics.Canvas
import android.graphics.CornerPathEffect
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import com.android.kotlincoroutinemvvmdemo.R

/*
* FindHouseView
* */
class FindHouseView @JvmOverloads constructor(
    context: Context,
    attributeSet: AttributeSet? = null
) : BaseView(context, attributeSet) {

    private val mStrokeWidth = context.resources.getDimension(R.dimen.dp_3)

    private val mPaint0 by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            strokeCap = Paint.Cap.ROUND
            strokeJoin = Paint.Join.ROUND
            strokeWidth = mStrokeWidth
            style = Paint.Style.STROKE
            pathEffect = CornerPathEffect(mStrokeWidth * 2)
            color = context.resources.getColor(R.color.color_74ED0E)
        }
    }

    private val mPath0 by lazy {
        Path()
    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        setBackgroundColor(context.resources.getColor(R.color.color_F3F3F3))
        canvas?.apply {
            val cx = mWidth.toFloat() / 2
            val cy = mHeight.toFloat() / 2
            translate(cx, cy + (cy * 13 / 60 - cy * 2 / 7) / 2)
            mPath0.apply {
                reset()
                moveTo(-cx * 5 / 7, 0F)
                lineTo(0F, -cy * 5 / 7)
                lineTo(cx * 5 / 7, 0F)
            }
            drawPath(mPath0, mPaint0)

            save()
            translate(0F,cy / 5)
            mPath0.apply {
                reset()
                arcTo(
                    -cx * 7 / 12,
                    -cy * 7 / 12,
                    cx * 7 / 12,
                    cy * 7 / 12,
                    10F,
                    160F,
                    true
                )
            }
            drawPath(mPath0, mPaint0)
            restore()
        }
    }
}